<template>
  <div class="auto">
    <div class="row app-row">
      <div class="col-xs-3">
        <p class="text-left">抄表员</p>
      </div>
      <div class="col-xs-9">
        {{userInfo.name}}
      </div>
    </div>
    <div class="row app-row">
      <div class="col-xs-3">
        <p class="text-left">起时间</p>
      </div>
      <div class="col-xs-9">
        <datepicker
           :value.sync="model.startDate"
           :format="'yyyy-MM-dd'"
           v-model="model.startDate"
           :show-reset-button="reset" placeholder="请输入起时间">
         </datepicker>
        <!-- <input type="text" class="search_input" v-model="model.startDate" placeholder="请输入起下发时间"/> -->
      </div>
    </div>
    <div class="row app-row">
      <div class="col-xs-3">
        <p class="text-left">止时间</p>
      </div>
      <div class="col-xs-9">
        <datepicker
           :value.sync="model.endDate"
           :format="'yyyy-MM-dd'"
           v-model="model.endDate"
           :show-reset-button="reset" placeholder="请输入止时间">
         </datepicker>
        <!-- <input type="text" class="search_input" v-model="model.endDate" placeholder="请输入止下发时间"/> -->
      </div>
    </div>
    <div class="row app-row">
      <div class="col-xs-3">
        <p class="text-left">地址</p>
      </div>
      <div class="col-xs-9">
        <input type="text" class="search_input" v-model="model.f_address" placeholder="请输入地址"/>
      </div>
    </div>
    <div class="row app-row">
      <div class="col-xs-3">
        <p class="text-left">抄表单条数</p>
      </div>
      <div class="col-xs-9">
        {{handcount}}
      </div>
    </div>
    <div class="row" style="margin-top: 20px;">
      <button type="button" class="btn btn-danger btn-lg" style="width: 100%;" @click="downHand()">抄表单下载</button>
    </div>
    <div class="auto" style="padding-top: 20px;">
      <hand-info v-if="show" :data="handinfo"></hand-info>
    </div>
    <div class="auto" v-if="!show">
      <p class="text-warning" style="padding: 0 10px">
        暂无可操作的抄表信息
      </p>
    </div>
  </div>
</template>
<script>
  import AppData from '../../stores/AppData'
  import * as Util from '../Util'
  export default {
    title: '计划管理',
    data () {
      return {
        model: {
          startDate: '',
          endDate: '',
          f_address: ''
        },
        userInfo: {},
        handMeterInfo: [],
        show: false,
        handinfo: [],
        handcount: 0
      }
    },
    ready () {
      // 获取抄表源信息
      this.userInfo = Object.assign({}, this.userInfo, AppData.loginUser)
      this.model.startDate = `${Util.toStandardYearMonth()}-01`
      this.model.endDate = Util.toStandardDateString()
    },
    methods: {
      downHand () {
        // TODO: 先检查网络情况

        if (this.model.startDate === '') {
          this.model.startDate = `${Util.toStandardYearMonth()}-01`
        }
        if (this.model.endDate === '') {
          this.model.endDate = Util.toStandardDateString()
        }
        let condition = ''
        if (this.model.f_address === '') {
          condition = '1 = 1'
        } else {
          condition = `1 = 1 and f_address like '${this.model.f_address}%'`
        }
        // `${this.userInfo.name}`
        let result = this.$androidUtil.bzLogic('downHandMeterInfo', {startDate: `${this.model.startDate}`, endDate: `${this.model.endDate}`, condition: condition, f_inputtor: `${this.userInfo.name}`})
        if (result.state === 0) {
          // 所有抄表但信息
          if (result.data.length > 0) {
            this.handcount = result.data.length
            this.handinfo = [...result.data]
            this.show = true
            HostApp.alert(`下载抄表单信息成功，本次下载${result.data.length}条抄表单，您可前往抄表管理进行抄表！` )
          } else {
            HostApp.alert('无可下载的抄表单信息！')
          }
        } else {
          HostApp.alert('下载失败！')
        }
      }
    }
  }
</script>
<style>
  .search_input {
    border: 0;
    outline: none;
  }
  .app-row {
    background-color: white;
    padding: 10px 10px 0 10px;
    border-bottom: 1px solid rgba(235, 235, 235, 0.5);
  }
</style>
